local skel = fk.CreateSkill({
  name = "kpaI__tianyi",
})

Fk:loadTranslationTable{
  ["kpaI__tianyi"] = "天义",
  [":kpaI__tianyi"] = "出牌阶段限一次，你可拼点，若你赢，则你本阶段可额外使用一张【杀】，且使用【杀】可指定至多两个目标，若未赢，你失去1点体力。",

  ["#kpaI__tianyi"] = "天义：与一名角色拼点，若赢，你使用【杀】获得增益，若没赢，本回合你不能使用【杀】",
  ["@kpaI__pujikpaI__tianyi-phase"] = "天义：",
  ["@kpaI__pujikpaI__dingxue"] = "订血：",

  ["$kpaI__tianyi1"] = "我当要替天行道！",
  ["$kpaI__tianyi2"] = "请助我一臂之力！",
}
skel:addAcquireEffect(function (self, player, is_start)
  if not table.contains(player:getTableMark("@kpaI__puji"..skel.name.."-phase"),tostring(player.hp)) then
    player:setSkillUseHistory("kpaI__tianyi",0,Player.HistoryPhase)
  else
    player:setSkillUseHistory("kpaI__tianyi",1,Player.HistoryPhase)
  end
end)

skel:addEffect("active", {
  mute = true,
  prompt = "#kpaI__tianyi",
  max_phase_use_time = 1,
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and player:canPindian(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    player.room:notifySkillInvoked(player, skel.name)
    if math.random(1,2) == 1 then
      player:broadcastSkillInvoke("kpaI__puji",5)
    else
      player:broadcastSkillInvoke("kpaI__dingxue",5)
    end
    room:addTableMarkIfNeed(player,"@kpaI__puji"..skel.name.."-phase",tostring(player.hp))
    local target = effect.tos[1]
    local pindian = player:pindian({target}, skel.name)
    if player.dead then return end
    if pindian.results[target].winner == player then
      room:addPlayerMark(player, "kpaI__tianyi-turn", 1)
    else
      room:loseHp(player,1)
    end
  end,
})
skel:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("kpaI__tianyi-turn") > 0 and scope == Player.HistoryPhase then
      return 1
    end
  end,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:getMark("kpaI__tianyi-turn") > 0 then
      return 2
    end
  end,
})


return skel
